package org.suyafei.component;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.suyafei.enums.ProductOrderPayTypeEnum;
import org.suyafei.vo.PayInfoVO;

/**
 * @author 宿某人
 * @Date: 2022/03/03/16:57
 * @Description:
 */
@Component
@Slf4j
public class PayFactory {


    @Autowired
    private AliPayStrategy aliPayStrategy;

    @Autowired
    private WeChatPayStrategy weChatPayStrategy;
    /**
     * 简单工厂，创建支付
     * @param payInfoVO
     * @return
     */
    public String pay(PayInfoVO payInfoVO) {

        String payType = payInfoVO.getPayType();

        if (ProductOrderPayTypeEnum.ALI_PAY.name().equals(payType)) {
            //TODO 支付宝支付
        } else if (ProductOrderPayTypeEnum.WECHAT_PAY.name().equals(payType)) {
            //微信支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(weChatPayStrategy);
            return payStrategyContext.executeUnifiedOrder(payInfoVO);
        }

        return "";
    }

    /**
     * 简单工厂，查询订单状态
     * @param payInfoVO
     * @return
     */
    public String queryPayStatus(PayInfoVO payInfoVO) {

        String payType = payInfoVO.getPayType();

        if (ProductOrderPayTypeEnum.ALI_PAY.name().equals(payType)) {
            //TODO 支付宝支付
        } else if (ProductOrderPayTypeEnum.WECHAT_PAY.equals(payType)) {
            //微信支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(weChatPayStrategy);
            return payStrategyContext.executeQueryPayStatus(payInfoVO);
        }

        return "";
    }

    /**
     * 简单工厂，退款
     * @param payInfoVO
     * @return
     */
    public String refund(PayInfoVO payInfoVO) {

        String payType = payInfoVO.getPayType();

        if (ProductOrderPayTypeEnum.ALI_PAY.name().equals(payType)) {
            //TODO 支付宝支付
        } else if (ProductOrderPayTypeEnum.WECHAT_PAY.equals(payType)) {
            //微信支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(weChatPayStrategy);
            return payStrategyContext.executeRefund(payInfoVO);
        }

        return "";
    }


    /**
     * 简单工厂，关单
     * @param payInfoVO
     * @return
     */
    public String closeOder(PayInfoVO payInfoVO) {

        String payType = payInfoVO.getPayType();

        if (ProductOrderPayTypeEnum.ALI_PAY.name().equals(payType)) {
            //TODO 支付宝支付
        } else if (ProductOrderPayTypeEnum.WECHAT_PAY.equals(payType)) {
            //微信支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(weChatPayStrategy);
            return payStrategyContext.executeCloseOder(payInfoVO);
        }

        return "";
    }
}
